package cn.edu.jju.psytest.web;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.edu.jju.psytest.model.util.EntityVoConverter;
import cn.edu.jju.psytest.model.vo.QuizRecordVo;
import cn.edu.jju.psytest.model.vo.UserVo;
import cn.edu.jju.psytest.service.QuizRecordService;

@SuppressWarnings("restriction")
@Controller
@RequestMapping("/quizRecord")
public class QuizRecordController {

	private QuizRecordService quizRecordService;

	@RequestMapping(method = RequestMethod.POST)
	@ResponseBody
	public String createQuizRecord(QuizRecordVo quizRecordVo, HttpSession session) {
		String studentId = ((UserVo)session.getAttribute("userVo")).getUsername();
		quizRecordService.saveQuizRecord(EntityVoConverter
				.getQuizRecord(quizRecordVo, studentId));
		return "createRecordSuccess";
	}
	
	@RequestMapping(value="/quizzesTime", method = RequestMethod.GET)
	@ResponseBody
	public String getQuizTestTime() {
		return quizRecordService.getQuizTestTime();
	}
	
	/**
	 * Getters And Setters
	 */
	public QuizRecordService getQuizRecordService() {
		return quizRecordService;
	}

	@Resource
	public void setQuizRecordService(QuizRecordService quizRecordService) {
		this.quizRecordService = quizRecordService;
	}
}
